package dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import model.VoyageCar;

@Stateless
public class VoyageCarDaoImpl implements IVoyageCarDao {

	@PersistenceContext(unitName = "putravel")
	EntityManager em;

	@Override
	public VoyageCar find(String depart, String arrivee) {
		VoyageCar resultat;
		Query q = em
				.createQuery("select v from VoyageCar v where v.villedepart=:depart and v.villearrivee=:arrivee");
		q.setParameter("depart", depart);
		q.setParameter("arrivee", arrivee);
		try {
			resultat = (VoyageCar) q.getSingleResult();
			return resultat;
		} catch (javax.persistence.NoResultException e) {
			return null;
		}
	}

}
